//
//  MyTeamsViewController.m
//  LanQiuQuan
//
//  Created by TonyGenius on 16/4/10.
//  Copyright © 2016年 Rip. All rights reserved.
//

#import "MyTeamsViewController.h"
#import "Marco.h"

@interface MyTeamsViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    XMTabBarController *_tab;
    NSMutableArray *_myTeamList;
    NSString *_userid;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation MyTeamsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    _myTeamList = [NSMutableArray array];
    [self initTableView];
//    self.automaticallyAdjustsScrollViewInsets = NO;
    
}

- (void)viewWillAppear:(BOOL)animated
{
    _tab = (XMTabBarController *)self.tabBarController;
    [_tab xmTabBarHidden:YES animated:YES];
}

- (void)initTableView
{
    [_tableView registerNib:[UINib nibWithNibName:@"myTeamsTableViewCell" bundle:nil] forCellReuseIdentifier:kMYTEAMSCELL];
    __weak MyTeamsViewController *weakSelf = self;
    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf requestToTop];
    }];
    [_tableView.mj_header beginRefreshing];
}

- (void)requestToTop
{
    _userid = @"2";
    NSString *url = [NSString stringWithFormat:@"%@%@",KURLFORMYTEAM,_userid];
    [NetWorkEngin getRequestWithParametes:url andBody:nil andFinishBlock:^(NSDictionary *respondData, NSError *error) {
        [_myTeamList removeAllObjects];
        
        [_myTeamList addObjectsFromArray:[jsonHelper jsonForCityTeamWithDictionary:respondData]];
        [_tableView.mj_header endRefreshing];
        [_tableView reloadData];
        
    }];
}

#pragma mark -UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    myTeamsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myteams" forIndexPath:indexPath];
    TeamModel *model = _myTeamList[indexPath.row];
    cell.teamName.text = model.name;
    cell.winTimes.text = [NSString stringWithFormat:@"胜:%@",model.winTimes];
    cell.teamPlayers.text = [NSString stringWithFormat:@"成员:%@",model.peopleCount];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _myTeamList.count;
}

#pragma mark -UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 105;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
